import {apiDictOptionEnumValue, apiUserInfo} from "@/api/system.js";
import useUserStore from "@/common/store/userStore.js";
import {ref, toRefs} from "vue";

export function refreshUserInfo() {
    return apiUserInfo().then(res => {
        useUserStore().userInfo = res.data
        return res.success;
    });
}

/**
 * 异步获取字典值
 */
export function asDict(...keys) {
    let ref_ = ref({});
    return (() => {
        keys.forEach((key, index) => {
            ref_.value[key] = [];
            apiDictOptionEnumValue({key}).then(res => {
                ref_.value[key] = JSON.parse(res.data)
            })

        })

        return toRefs(ref_.value);
    })()
}

